<!-- 分账分拥（临时） -->
<template>
  <div class="app-container">
    <el-form class="alone-business" :model="queryData" ref="queryDataRef" :inline="true" label-width="90px">
      <el-form-item label="采购单编号" prop="purchaseOrderNo ">
        <el-input v-model="queryData.purchaseOrderNo" placeholder="请输入" clearable style="width: 200px" />
      </el-form-item>
      <el-form-item label="工厂名称" prop="factoryName">
        <el-input v-model="queryData.factoryName" placeholder="请输入" clearable style="width: 200px" />
      </el-form-item>
      <el-form-item label="商家名称" prop="businessName">
        <el-input v-model="queryData.businessName" placeholder="请输入" clearable style="width: 200px" />
      </el-form-item>
      <el-form-item label="代理商名称" prop="agentName">
        <el-input v-model="queryData.agentName" placeholder="请输入" clearable style="width: 200px" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="searchData">查询</el-button>
        <el-button icon="Refresh" @click="reset">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="tableData" highlight-current-row>
      <el-table-column property="purchaseOrderNo" label="采购单编号" width="180"></el-table-column>
      <el-table-column property="businessName" label="商家名称" width="220"></el-table-column>
      <el-table-column property="factoryName" label="工厂名称" width="220"></el-table-column>
      <el-table-column property="agentName" label="代理商名称" width="220"></el-table-column>
      <el-table-column property="totalMoney" label="本次商家支付总金额" width="160"></el-table-column>
      <el-table-column property="toAgentMoney" label="本次商家支付给代理商的金额" width="220"></el-table-column>
      <el-table-column property="inMoney" label="本次商家支付给工厂的金额" width="220"></el-table-column>
      <el-table-column property="receiptDate" label="收款日期" width="180"></el-table-column>
      <el-table-column property="splitStatus" label="财务分账状态" width="120">
        <template #default="{ row }">
          <div>
            {{
              row.splitStatus == 0
                ? "初始化"
                : row.splitStatus == 1
                  ? "分账中"
                  : row.splitStatus == 2
                    ? "分账成功"
                    : row.splitStatus == 3
                      ? "部分分账成功"
                      : "--"
            }}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="分账">
        <el-table-column property="toFactoryMoneyTotal" label="分账-平台金额" width="120"></el-table-column>
        <el-table-column property="depositRatio" label="保证金金额扣除比例" width="150"></el-table-column>
        <el-table-column property="depositAmount" label="保证金金额" width="120"></el-table-column>
        <el-table-column property="factorySalesRatio" label="工厂营销分佣扣除比例" width="160"></el-table-column>
        <el-table-column property="factorySalesAmount" label="工厂营销分佣金额" width="140"></el-table-column>
        <el-table-column property="factoryPurchaseRatio" label="工厂集采分佣扣除比例" width="160"></el-table-column>
        <el-table-column property="factoryPurchaseAmount" label="工厂集采分佣金额" width="140"></el-table-column>
      </el-table-column>
      <el-table-column fixed="right" label="操作" min-width="120">
        <template #default="scope">
          <el-button link type="primary" size="small" @click.prevent="toPath(scope.row)"> 详情 </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination :total="listTotal" v-model:page="queryData.current" v-model:limit="queryData.size" @pagination="getTable" />
  </div>
</template>
<script setup>
import { getPage } from "@/api/system/rebateRules/paymentDistribution/paymentDistribution";
import { onMounted } from "vue";

const router = useRouter();

defineOptions({
  name: "PaymentDistribution"
});

// 搜索条件
const queryData = ref({
  current: 1,
  size: 10
});
const tableData = ref([]);
const listTotal = ref(0);

// 查询
const searchData = () => {
  getTable();
};

// 搜索重置
const reset = () => {
  queryData.value = {
    purchaseOrderNo: "",
    factoryName: "",
    businessName: "",
    agentName: "",
    current: 1,
    size: 10
  };
  getTable();
};
const getTable = () => {
  getPage(queryData.value).then(res => {
    tableData.value = res.data.list;
    listTotal.value = res.data.total;
  });
};

const toPath = row => {
  console.log(row);
  router.push({
    path: "/rebateRules/paymentDistributionDetails",
    query: {
      splitManageId: row.splitManageId
    }
  });
};
onMounted(() => {
  getTable();
});
</script>
<style scoped lang="scss"></style>
